<?php 

Class Mysql{
    
    public $dbSource=null;
    
    public  $dbConfig=[];
    
    public  function __construct(){
        $this->dbSource=new Swoole\Mysql;
        
        $this->dbConfig=[
            'host' =>'127.0.0.1',
            'prot' =>'3306',
            'user'=>'root',
            'password'=>'ok',
            'database'=> 'swoole',
            'charset'=>'utf8',
        
        ];
    }
    
    public function execute($id,$username){
        $this->dbSource->connect($this->dbConfig,function($db,$result){
           if($result==false){
               var_dump($db->connect_error);
           }
           $sql="select * from user";
           
           $db->query($sql,function($db,$result){
              if($result===false){ 
                  
              }else if($result===true){   //add update delete
                  
              }else{
                  var_dump($result);
              }
              $db->close();
           });
            
           
          
            
        });
        
        return true;
    }
}

$obj=new Mysql();
$obj->execute("1", "asd");